#pragma once

#include <AVUIButtonBase.h>

namespace AVUI {

class ControlTemplate;
class DispatcherTimer;
class RepeatButton : public ButtonBase
{
public:
    RepeatButton() { };
    ~RepeatButton() { };

    DECLARE_ELEMENT(RepeatButton, ButtonBase);

    DECLARE_DEPENDENCY_PROPERTY(Delay);
    int get_Delay() { return AVUI::UnboxValue<int>(GetValue(get_DelayProperty())); }
    void set_Delay(int value) { SetValue(get_DelayProperty(), AVUI::BoxValue(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(Interval);
    int get_Interval() { return AVUI::UnboxValue<int>(GetValue(get_IntervalProperty())); }
    void set_Interval(int value) { SetValue(get_IntervalProperty(), AVUI::BoxValue(value)); } 

protected:

    virtual void OnMouseLeftButtonDown(MouseButtonEventArgs* pArgs);
    virtual void OnMouseLeftButtonUp(MouseButtonEventArgs* pArgs);
    virtual void OnMouseEnter(MouseEventArgs* pArgs);
    virtual void OnMouseLeave(MouseEventArgs* pArgs);
    virtual void OnKeyDown(KeyEventArgs* pArgs);


private:
    static void StaticConstructor();

    static int GetKeyboardDelay();
    static int GetKeyboardSpeed();

    void StopTimer();
    void StartTimer();
    void OnTimeout(Object* pSender, EventArgs* pArgs);

    bool HandleIsMouseOverChanged();

    TRefCountedPtr<DispatcherTimer> m_pTimer;
};

}; // namespace AVUI
